package
{
	import flash.display.Sprite;
	import flash.events.KeyboardEvent;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	public class Stake extends Sprite
	{
		private const stakes:Array = [1, 2, 5, 10, 15, 20, 50, 100];
		
		private const WIDTH:uint = 100;
		
		private var stakeIndex:int = -1;
		private var stakeField:TextField;
		
		[Embed(source="assets/tab.gif")]
		private var tab:Class;
		private var tabSprite:Sprite;
		
		public function Stake()
		{
			tabSprite = new Sprite();
			tabSprite.addChild(new tab());
			tabSprite.x = -40;
			tabSprite.y = 15;
			this.addChild(tabSprite);
			
			var label:TextField = new TextField();
			label.selectable = false;
			label.text = "STAKE";
			label.width = WIDTH;
			label.y = -5;
			
			var tf:TextFormat = new TextFormat();
			tf.font = "Tahoma";
			tf.size = 20;
			tf.align = "center";
			
			label.setTextFormat(tf);
			
			this.addChild(label);
			
			this.graphics.beginFill(0xC0C0C0);
			this.graphics.drawRect(0, 20, WIDTH, 40);
			this.graphics.endFill();
			
			stakeField = new TextField();
			stakeField.selectable = false;
			stakeField.y = 13;
			
			var stf:TextFormat = new TextFormat();
			stf.font = "Tahoma";
			stf.size = 40;
			stf.align = "center";
			
			stakeField.setTextFormat(stf);
			stakeField.defaultTextFormat = stf;
			
			setNextStakeValue();
			
			this.addChild(stakeField);
		}
		
		public function setNextStakeValue():void
		{
			stakeIndex++;
			
			if (stakes.length == stakeIndex)
			{
				stakeIndex = 0;
			}
			
			stakeField.text = String(stakes[stakeIndex]);
		}
		
		public function toggleTab():void
		{
			tabSprite.visible = !tabSprite.visible;
			
		}
		
	}
}